<!DOCTYPE html>
<?php session_start() ?>
<html>
<head>
	<title>SearchBook</title>
	<meta charset="UTF-8" />
	<link href="index.css" type="text/css" rel="stylesheet" media="screen" />
	<link href="css/searchbook.css" type="text/css" rel="stylesheet" media="screen" />
	<script src="js/validator.js" type="text/javascript"></script>
</head>
<body>
<div class="topbar">
                <div class="loginfo">
                    <ul>
                        <li>
                            <?php
                            if(!isset($_SESSION["session_username"]))
                                {
                                ?>
							
                                <form action="login.php" method="post" onsubmit="return checkAuth()">
								用户名<input type = "text" name="username"/>
								密码<input type = "password" name="password" /> 
                                <input type="submit" value="登陆" />
                            </form>
                            <input type="button" value="注册" onclick="window.location.href = 'RegisterSite.php'"></input>
                            
                            <?php
                            }
                            else{
                                $name = $_SESSION["session_username"];
                                ?>
                                <?=$name?>
                                <?php
									if(isset($_SESSION["session_admin"]) && $_SESSION["session_admin"] == true)
									{
								?>
									<input type="button" value="用户管理" onclick="window.location.href ='UserControl.php'"/>
								<?php
									}
                                ?>
                                <input type="button" value="注销" onclick="window.location.href ='Logout.php'"/>
                                <?php
                                }
                                ?>
                        </li>
                    </ul>
                </div>
                <div class="globalitems">
                    <ul>
                        <li>
							<a href="index.php">首页</a>
                        </li>
                        <li>
                            <a href="SearchBook.php?allbook=true">书库</a>
                        </li>
                        <li>
                            <a href="showGroup.php">我的群组</a>
                        </li>
                        <li>
							<a href="index.php">随便看看</a>
                        </li>    
                    </ul>
                </div>
            </div>
            <div id="main">
            	<div id="maintitle">
            		搜索结果：
            	</div>
<?php
	if(isset($_REQUEST["allbook"]))
	{
		include_once 'Book.php';
		$booklist = Book::findBookLikeName(null);
		// echo count($booklist);
		for($count = 0;$count < count($booklist);$count ++)
		{
			$pic = $booklist[$count]->getFace();
			$intro = $booklist[$count]->getIntro();
			$bkname = $booklist[$count]->getName();
?>
	<div class="result">
		<div class="bookimage">
		<a href="ShowBook.php?bookname=<?=$bkname?>"><img src="<?=$pic?>"></img></a>
		</div>
		<div class="introduce"><p><?=$intro?></p></div>
		<div class="clearfix"></div>
	</div>

<?php
		}
	}
	else
	{
		$bookname = $_GET["consult-book-name"];
		include_once 'Book.php';
		$booklist = Book::findBookLikeName($bookname);
		for($count = 0;$count < count($booklist);$count ++)
		{
			$pic = $booklist[$count]->getFace();
			$intro = $booklist[$count]->getIntro();
			$bkname = $booklist[$count]->getName();
?>
	<div class="result">
		<div class="bookimage">
			<a href="ShowBook.php?bookname=<?=$bkname?>"><img src="<?=$pic?>"></img></a>
			</div>
		<div class="introduce"><p><?=$intro?></p></div>
		<div class="clearfix"></div>
	</div>
<?php
		}
	}
?>
</div>
</body>
</html>